home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE25
/
EX4.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-23
|
3KB
|
68 lines
#include <genstub.c>
LPARAM CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LONG lParam )
{
switch (message)
{
case WM_COMMAND: // process menu items
switch ( LOWORD( wParam ) )
{
case IDM_TEST:
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
TCHAR szBuffer[128];
// initialize structures
ZeroMemory( &si, sizeof(STARTUPINFO) );
ZeroMemory( &pi, sizeof(PROCESS_INFORMATION) );
si.cb=sizeof( STARTUPINFO );
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
CreateProcess( "C:\\windows\\calc.exe", "", NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi );
WaitForInputIdle( GetCurrentProcess(), INFINITE );
// loop until process terminates
if (pi.hProcess) {
DWORD dwExitCode = STILL_ACTIVE;
while (dwExitCode == STILL_ACTIVE) {
WaitForSingleObject( pi.hProcess, 1000 );
GetExitCodeProcess( pi.hProcess, &dwExitCode );
SendMessage( hWnd, WM_USER, 0, (LPARAM)"Waiting for Calc to Finish" );
}
SendMessage( hWnd, WM_USER, 0, (LPARAM)"Calc is Finished" );
}
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_USER:
{ // Message to show synchronization actions.
TCHAR szBuffer[101];
static int row = 0;
static int msg_num = 1;
HDC hDC = GetDC( hWnd );
FillMemory( szBuffer, 100, 32 );
TextOut( hDC, 0, row, szBuffer, 100 );
wsprintf( szBuffer, "%3d: %s", msg_num++, (LPTSTR)lParam );
TextOut( hDC, 0, row, szBuffer, lstrlen( szBuffer ) );
if ( row > 200 )
row = 0;
else
row += 20;
ReleaseDC( hWnd, hDC );
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, message, wParam, lParam );
}
return (NULL);
}